<template>
	<view class="pagebody borderbox">
		<view class="topimg align-center justify-center">
			<image class="toplogo" src="@/static/images/wxcode/topimg.png" mode=""></image>
		</view>
		
		<view class="codebox flex-col justify-center align-center">
			<view class="fwbold text-al-center color303b39 fz48">
				免费获取最新资料
			</view>
			<image style="width: 22rpx;height: 20rpx;margin: 24rpx 0;" src="@/static/images/wxcode/down.png" mode=""></image>
			<view class="code flex-col justify-center align-center">
				<view class="justify-center align-center" style="width:100%;height: 382rpx;border-radius: 24rpx;background: #fff;">
					<img  @click="previewImage(imgurl)" :show-menu-by-longpress="true" style="width: 330rpx;height: 330rpx;" :src=" imgurl" mode=""/>
					<!-- <img  @longpress="startScanCode()" :show-menu-by-longpress="true" style="width: 330rpx;height: 330rpx;" :src=" imgurl" mode=""/> -->
				</view>
				<view class="fz36 colorfff" style="margin-top: 24rpx;">
					{{disname}}的群二维码
				</view>
			</view>
			<view class="addlc fz32 color303b39 mt45">
				<p style="color:#00D9B2; font-weight: bold; justify-content: center;">添加流程</p>
				<p><span>1</span> 点击图片预览</p>
				<p><span>2</span>长按二维码识别添加</p>
				
			</view>
		</view>

	
	
	</view>
</template>

<script>
	import {
		getDiseaseById
	} from '@/api/api.js'
	import {
		getInfo
	} from '@/api/login'
	export default {
		onLoad() {
			// 获得屏幕最大高度
			let systemInfo = uni.getSystemInfoSync();
			this.maxHeight = systemInfo.windowHeight + 100 + "px";
	
		},
		data() {
			return {
				// maxHeight: '',
				disname:'',
				imgurl:''
			}
		},
		mounted() {
			this.getuser()
		},
		methods: {
			getuser() {
				getInfo().then(res => {
					let disid = res.userDocument.diseaseId
					this.disname = res.userDocument.diseaseName
					getDiseaseById(disid).then(response=>{
						console.log(response)
						this.imgurl = this.$config.baseUrl + response.data.iconpath
						console.log(this.imgurl)
						
					})
				})
			},
			// 启动扫码
			    startScanCode() {
					console.log("长按了")
			      uni.scanCode({
			        success: (res) => {
			          uni.showToast({
			            title: '扫码成功',
			            icon: 'success'
			          });
			          console.log('二维码内容:', res.result);
			        },
			        fail: (err) => {
			          uni.showToast({
			            title: '扫码失败',
			            icon: 'none'
			          });
			          console.error('扫码失败:', err);
			        }
			      });
			    },
			
			 previewImage(imgPath){
			       				uni.previewImage({
			       					urls: [imgPath],
			       					current: imgPath,
			       					indicator: 'default',
			       					loop: false,
			       					longPressActions: {
			       						itemList: ['打开微信扫一扫', '分享至微信好友', '保存到相册'],
			       						success: function(data) {
			       							if (data.tapIndex === 0) {
			       								uni.downloadFile({ 
			       									url: imgPath, 
			       									success: (res) => {
			       										if (res.statusCode === 200) {
			       											console.log('下载成功', res);
			       											uni.saveImageToPhotosAlbum({
			       												filePath: res.tempFilePath,
			       												success: function(res) {
			       													uni.showToast({
			       														title: "操作成功",
			       														icon: 'success'
			       													})
			       													if (plus.os.name == "iOS") {
			       														plus.runtime.openURL(
			       															"weixin://scanqrcode"
			       														)
			       													} else if (plus.os.name ==
			       														"Android") {
			       														var Intent = plus.android
			       															.importClass(
			       																"android.content.Intent"
			       															);
			       														var ComponentName = plus
			       															.android.importClass(
			       																'android.content.ComponentName'
			       															)
			       														var intent = new Intent();
			       														intent.setComponent(
			       															new ComponentName(
			       																"com.tencent.mm",
			       																"com.tencent.mm.ui.LauncherUI"
			       															));
			       														intent.putExtra(
			       															"LauncherUI.From.Scaner.Shortcut",
			       															true);
			       														intent.setFlags(335544320);
			       														intent.setAction(
			       															"android.intent.action.VIEW"
			       														);
			       														var main = plus.android
			       															.runtimeMainActivity();
			       														main.startActivity(intent);
			       													}
			       												}
			       											})
			       										}
			       									},
			       									fail: (res) => {
			       										uni.showToast({
			       											title: "操作失败",
			       											icon: 'error'
			       										})
			       									}
			       								});
			       							}
			       							if (data.tapIndex === 1) {
			       								uni.share({
			       									provider: "weixin",
			       									scene: "WXSceneSession",
			       									type: 2,
			       									imageUrl: imgPath,
			       									success: function(res) {
			       										uni.showToast({
			       											title: "分享成功",
			       											icon: 'success'
			       										})
			       									},
			       									fail: function(err) {
			       										uni.showToast({
			       											title: "分享失败",
			       											icon: 'error'
			       										})
			       									}
			       								});
			       							}
			       							if (data.tapIndex === 2) {
			       								uni.downloadFile({
			       									url: imgPath, 
			       									success: (res) => {
			       										if (res.statusCode === 200) {
			       											console.log('下载成功', res);
			       											uni.saveImageToPhotosAlbum({
			       												filePath: res.tempFilePath,
			       												success: function(res) {
			       													uni.showToast({
			       														title: "保存成功",
			       														icon: 'success'
			       													})
			       												}
			       											})
			       										}
			       									},
			       									fail: (res) => {
			       										uni.showToast({
			       											title: "保存失败",
			       											icon: 'error'
			       										})
			       									}
			       								});
			       							}
			        
			       						},
			       						fail: function(err) {
			       							console.log(err.errMsg);
			       						}
			       					},
			       					success: res => {
			       						// console.log('res', res);
			       					},
			       					fail: err => {
			       						console.log('err', err);
			       					}
			       				});
			       			
			    },
				
		}
	};
</script>

<style lang="scss" scoped>
	.pagebody {
		overflow: hidden;
		height: 100vh;
		background-image: url('/static/images/wxcode/pagebg.png');
		background-repeat: no-repeat;
		background-size: cover;
		padding: 0 75rpx;
		// background-repeat: repeat;
		// /* 平铺背景 */
		// background-size: auto;
		/* 图片保持原始大小 */
		.topimg{
			margin-top: 115rpx;
			.toplogo{
				width: 540rpx;
				height: 97rpx;
			}
		}
		.codebox{
			margin-top: 62rpx;
			background: #fff;
			border-radius: 32rpx;
			padding: 80rpx 88rpx;
			.code{
				width: 100%;
				background: #00D9B2;
				border-radius: 32rpx;
				padding: 24rpx 24rpx 32rpx;
			}
			.addlc{
				p{
					display: flex;
					align-items: center;
					margin-bottom:16rpx ;
					span{
						margin-right: 8rpx;
						font-size:26rpx; 
						color: #fff;
						text-align: center;
						line-height: 32rpx;
						display: inline-block;
						border-radius: 50%;
						background: linear-gradient(252deg, #00D9B2 0%, #00F3C8 100%);
						width: 32rpx;
						height: 32rpx;
					}
				}
			}
		}
	
	}
</style>